package com.wang.common;

import com.wang.bean.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author wangf
 * @Description 自定义异常处理
 * @Date 2023/9/3 20:24
 */

@RestControllerAdvice
public class ExceptionAdaptController {

    /**
     * 处理运行时异常
     * @param e
     * @return
     */
    @ExceptionHandler({RuntimeException.class})
    public Result runtimeException(RuntimeException e) {
        e.printStackTrace();
        return Result.fail();
    }

    /**
     * 处理其他异常
     * @param e
     * @return
     */
    @ExceptionHandler({Exception.class})
    public Result Exception(RuntimeException e) {
        e.printStackTrace();
        return Result.fail();
    }
}
